<#include "/layout/layout.ftl">
<#import "/layout/macro.ftl" as macro>
<#import "/layout/select.ftl" as my/>
<#assign css>
<#--此ftl中用到的css-->
    <link rel="stylesheet" href="/assets/vendor/bootstrap-timepicker/css/bootstrap-timepicker.min.css">
    <link rel="stylesheet" href="/assets/vendor/fileinput/css/fileinput.min.css">
    <style>
        .child_type {
            display: none;
        }
    </style>
</#assign>
<#assign js>
<#--此ftl中用到的js-->
    <script src="/assets/vendor/bootstrap-timepicker/js/bootstrap-timepicker.min.js"></script>
    <script src="/assets/vendor/fileinput/js/fileinput.min.js"></script>
    <script src="/assets/vendor/fileinput/js/locales/zh.js"></script>
    <script type="text/javascript" src="/assets/vendor/bootstrap-timepicker/locales/bootstrap-timepicker.zh-CN.js"
            charset="UTF-8"></script>
    <script>
        $(".btn-submit").click(function () {
            // 校验表单合法
            var bootstrapValidator = $(".form-edit").data('bootstrapValidator');
            bootstrapValidator.validate();
            if (bootstrapValidator.isValid()) {
                $.ajax({
                    type: "POST",
                    url: "/agent/edit",
                    data: $(".form-edit").serialize(),
                    dataType: "JSON",
                    success: function (res) {
                        layer.msg(res.message, {
                            time: 2000
                        }, function () {
                            location.href = "/agent/index";
                        });
                    }
                });
            } else {
                return false;
            }
        });

        $('.form-edit').bootstrapValidator({
            message: '请输入有效值',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            }
        });

        $(function () {
            //Date picker
            $('#nightS').timepicker({
                autoclose: true,
                format: "HH:mm:ss",
                showMeridian: false,
                todayHighlight: true,
                language: "zh-CN"
            });
            $('#nightE').timepicker({
                autoclose: true,
                format: "HH:mm:ss",
                showMeridian: false,
                todayHighlight: true,
                language: "zh-CN"
            });
            $("#head_pic_file").fileinput({
                language: 'zh', //设置语言
                uploadUrl: "/upload/uploadImg", //上传的地址
                allowedFileExtensions: ['jpg', 'png', 'gif', 'jpeg'],//接收的文件后缀
                showUpload: true, //是否显示上传按钮
                showCaption: false,//是否显示标题
                showRemove: false, // 是否显示移除按钮
                maxFileCount: 1,//上传图片最大数量
                browseClass: "btn btn-primary", //按钮样式
                previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
                <#if (agent.headPic)?? && agent.headPic != "">
                initialPreview: [
                    "<img src='/${agent.headPic}' class='file-preview-image'>"
                ],
                </#if>
            });
            $("#head_pic_file").on("fileuploaded", function (event, data, previewId, index) {
                $("#headPic").val(data.response.data);
            });
        })
    </script>
</#assign>
<@layout title="编辑" active="agent">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            <#if isAdd>
                新增
            <#else>
                编辑
            </#if>
            <small>分站详细信息</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="/"><i class="fa fa-home"></i> 管理后台</a></li>
            <li><a href="/agent/index"><i class="fa fa-list-ul"></i> 分站管理</a></li>
            <li class="active"><i class="fa fa-edit"></i>
                <#if isAdd>
                    新增
                <#else>
                    编辑
                </#if>
            </li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <!-- Default box -->
                <div class="box  box-primary">
                    <form class="form-horizontal form-edit" method="post" action="agent/edit">
                        <div class="box-body">
                            <input type="hidden" id="id" name="id" value="${agent.id!}">
                            <input type="hidden" id="isAdd" name="isAdd" value="${isAdd?string('true','false')}">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">分站名称：</label>
                                <div class="col-sm-10">
                                    <input required placeholder="请输入区县名称" id="name" name="name" class="form-control"
                                           type="text" value="${agent.name!}">
                                </div>
                            </div>
                            <#--<div class="form-group">
                                <label class="col-sm-2 control-label">分站联系人：</label>
                                <div class="col-sm-10">
                                    <input required placeholder="请输入分站联系人" id="contact" name="contact"
                                           class="form-control" type="text" value="${agent.contact!}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">联系人头像：</label>
                                <div class="col-sm-10">
                                    <input type="file" id="head_pic_file" name="file">
                                    <input type="hidden" id="headPic" name="headPic" value="${agent.headPic}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">联系人手机号：</label>
                                <div class="col-sm-10">
                                    <input required placeholder="请输入联系人手机号" id="phone" name="phone" class="form-control"
                                           type="text" value="${agent.phone!}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">联系地址：</label>
                                <div class="col-sm-10">
                                    <input required placeholder="请输入联系地址" id="address" name="address"
                                           class="form-control" type="text" value="${agent.address!}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">开通状态：</label>
                                <div class="col-sm-10">
                                    <@my.select id="stat" datas=getDict('AGENT_STATUS')  value="${agent.stat!}" defaultValue="请选择状态"/>
                                </div>
                            </div>-->
                            <#--<div class="form-group">
                                <label class="col-sm-2 control-label">深夜服务开始时间：</label>
                                <div class="col-sm-10">
                                    <input required placeholder="请输入深夜服务开始时间" id="nightS" name="nightS"
                                           class="form-control" type="text" value="${agent.nightS!}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">深夜服务结束时间：</label>
                                <div class="col-sm-10">
                                    <input required placeholder="请输入深夜服务结束时间" id="nightE" name="nightE"
                                           class="form-control" type="text" value="${agent.nightE!}">
                                </div>
                            </div>-->
                            <div class="form-group">
                                <label class="col-sm-2 control-label">奖励金额：</label>
                                <div class="col-sm-10">
                                    <input required placeholder="请输入奖励金额" id="award" name="award" class="form-control"
                                           type="text" value="${agent.award!}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">取消订单扣款比例(%)：</label>
                                <div class="col-sm-10">
                                    <input required placeholder="请输入取消订单扣款比例" id="cancelOrder" name="cancelOrder"
                                           class="form-control" type="text" value="${agent.cancelOrder!}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">保证金：</label>
                                <div class="col-sm-10">
                                    <input required placeholder="保证金" id="margin" name="margin"
                                           class="form-control" type="number" value="${agent.margin!}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">跑腿自动取消时间（分钟）：</label>
                                <div class="col-sm-10">
                                    <input required placeholder="跑腿自动取消时间" id="paotuiCtime" name="paotuiCtime"
                                           class="form-control" type="number" value="${agent.paotuiCtime!}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">其他服务自动取消时间（分钟）：</label>
                                <div class="col-sm-10">
                                    <input required placeholder="其他服务自动取消时间" id="otherCtime" name="otherCtime"
                                           class="form-control" type="number" value="${agent.otherCtime!}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">自动派单改派次数：</label>
                                <div class="col-sm-10">
                                    <input required placeholder="自动派单改派次数" id="autoCount" name="autoCount"
                                           class="form-control" type="number" value="${agent.autoCount!}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">三公里内预计送达时间（分钟）：</label>
                                <div class="col-sm-10">
                                    <input required placeholder="起步时间" id="initTime" name="initTime"
                                           class="form-control" type="number" value="${agent.initTime!}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">每超一公里增加时间（分钟）：</label>
                                <div class="col-sm-10">
                                    <input required placeholder="起步公里外" id="extraTime" name="extraTime"
                                           class="form-control" type="number" value="${agent.extraTime!}">
                                </div>
                            </div>
                            <div class="box-footer">
                                <button type="button" class="btn btn-default btn-back">返回</button>
                                <button type="button" class="btn btn-info pull-right btn-submit">提交</button>
                            </div>

                    </form>
                </div>
                <!-- /.box -->
            </div>
        </div>
    </section>
    <!-- /.content -->
</@layout>
